<?php

namespace app\order\controller;

use app\api\logic\TestLogic;
use app\common\controller\PCBase;
use app\BaseController;
use app\order\logic\OrderSourceLogic;
use app\order\logic\OrderShipLogic;
use think\facade\Db;
use Throwable;
use app\common\library\Upload;
use util\Token;

class OrderSource extends PCBase
{


    public function initialize(): void
    {
        parent::initialize();
    }

    /**
     * index
     * @throws Throwable
     */
    public function index()
    {
        $params     = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        return $OrderSourceLogic->index($params);
    }
    /**
     * 运营标签列表
     * @throws Throwable
     */
    public function OperationLabelList()
    {
        $params     = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        return $OrderSourceLogic->OperationLabelList($params);
    }
    /**
     * 渠道标签列表
     * @throws Throwable
     */
    public function ChannelLabelList()
    {
        $params     = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        return $OrderSourceLogic->ChannelLabelList($params);
    }

    /**
     * export
     * @throws Throwable
     */
    public function export()
    {
        $params     = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $params['create_work_num'] = $this->getAdminTel();
        return $OrderSourceLogic->export($params);
    }



    /**
     * @desc    获取导出总数
     * @date    2024-08-15
     * @author  luckyXiong
     */
    public function getExportCount(){
        $params                    = $this->request->post();
        $params['create_work_num'] = $this->getAdminTel();
        return (new OrderSourceLogic())->getExportCount($params);
    }




    /**
    * @desc    编辑
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function edit()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();

        //日志
        $adminId = $this->getAdminId();
        $updateData = [];
        foreach ($post as $k=>$value) {
            $updateData[] = [
                'source_id' => $value["id"] ?? 0,
                'tag_source' => $value["tag_source"] ?? "",
                'tag_campaign' => $value["tag_campaign"] ?? "",
                'admin_id' => $adminId,
                'createtime' => time(),
                'shop_id' => 17,
            ];
        }
        Db::name('order_source_log')->insertAll($updateData);
        //日志

        $result = $OrderSourceLogic->edit($post);
        return $result;
    }
    /**
    * @desc    按渠道查看销售业绩
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function SalesPerformanceChannel()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $result = $OrderSourceLogic->SalesPerformanceChannel($post);
        return $result;
    }
    /**
    * @desc    按sku查看销售业绩
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function SalesPerformanceSku()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $result = $OrderSourceLogic->SalesPerformanceSku($post);
        return $result;
    }
    /**
    * @desc    按id查询附加信息
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function AdvertisingInquiry()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $result = $OrderSourceLogic->AdvertisingInquiry($post);
        return $result;
    }

    /**
    * @desc    订单业绩--多店铺规则
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function OrderAchievement()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $result = $OrderSourceLogic->OrderAchievement($post);
        return $result;
    }
    /**
    * @desc    订单业绩--批量修改
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function OrderAchievementEdit()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();
        $result = $OrderSourceLogic->OrderAchievementEdit($post);
        return $result;
    }

    

    /**
    * @desc    编辑
    * @date    2024/7/16
    * @author  zhangheng
    */
    public function wholePageModification()
    {
        $post = $this->request->post();
        $OrderSourceLogic = new OrderSourceLogic();

        //日志
        $adminId = $this->getAdminId();
        $updateData = [];
        foreach ($post['ids'] as $k=>$value) {
            $updateData[] = [
                'source_id' => $value ?? 0,
                'tag_campaign' => $post["tag_campaign"] ?? "",
                'admin_id' => $adminId,
                'createtime' => time(),
                'shop_id' => 17,
            ];
        }
        // Db::name('order_source_log')->insertAll($updateData);
        //日志

        $result = $OrderSourceLogic->wholePageModification($post);
        return $result;
    }

}
